export const normalizeDate = (date) => {
  let time = new Date(date)
  let y = time.getFullYear()
  let M = time.getMonth() + 1
  let d = time.getDate()
  let h = time.getHours()
  let m = time.getMinutes()
  let s = time.getSeconds()
  let res = [y, M, d, h, m, s].map(v => v.toString().padStart(2, 0))
  return res.slice(0, 3).join('/') + " " + res.slice(3).join(':')
}
//处理时间格式函数【年/月/日】
export const normalizeYmd = (date) => {
  let time = new Date(date)
  let y = time.getFullYear()
  let M = time.getMonth() + 1
  let d = time.getDate()
  let res = [y, M, d].map(v => v.toString().padStart(2, 0))
  return res.slice(0, 3).join('/')
}
//处理时间格式函数【时：分：秒】
export const normalizeHms = (date) => {
  let time = new Date(date)
  let h = time.getHours()
  let m = time.getMinutes()
  let s = time.getSeconds()
  let res = [h, m, s].map(v => v.toString().padStart(2, 0))
  return res.join(':')
}
//数字 处理为每3位逗号隔开
export const dealNumber = (num) => {
  if (num != 0 && num) {
    num = num + ""
    let decimalsStr = "";
    let splitList = num.split(".");
    //先处理小数部分
    if (splitList[1]) {
      //如果有2位小数则保留2位，只有1位则添0
      decimalsStr = decimalsStr.substring(0, 2).length == 2 ? decimalsStr.substring(0, 2) : decimalsStr.substring(0, 2) + "0";
    }
    //整数部分
    //将整数部分拆解为单个数字的数组倒序，然后拼装为新的数组，每3位数字进行一次匹配
    let intStrList = splitList[0].split("").reverse().join('').match(/(\d{1,3})/g);
    //将匹配后的数组用，拼接，再拆解为单个数字的数组，反转为原先数组形式，拼接为完整数字
    let intStr = intStrList.join(',').split('').reverse().join('');
    return intStr + decimalsStr;
  }
  return num
}